import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error

data = pd.read_csv('Ningde data.csv').drop('ts_code',axis=1)
target_column = 'close'
correlations = data.corr()[target_column].abs().sort_values(ascending=False)
# print(correlations)
selected_features = correlations[correlations > 0.2].index.tolist()
# print(selected_features)
x = data[selected_features].drop(target_column,axis=1)
y = data[target_column]
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=42)


rf_model  = RandomForestRegressor()
rf_model.fit(x_train,y_train)
feature_importances = pd.Series(rf_model.feature_importances_,index=x_train.columns)
print(feature_importances)
